// TypeScript file
module Fighter {

    /**
     * 音乐——郭启航
     */
    export class Music extends eui.Component {
        constructor() {
            super();
        }
        public sound: egret.Sound = new egret.Sound();
        public soundChannel: egret.SoundChannel;
        public PlayBool: boolean;
        public PlayBoolNow: boolean = true;
        public Play(string: string) {
            this.sound = RES.getRes(string);
            this.soundChannel = this.sound.play(0, 1);
            this.soundChannel.volume = 1;
            this.addEventListener(egret.Event.ENTER_FRAME, this.Update, this);
        }
        public Update() {
            if (!PrepareUI.PlayMusciBool && !this.PlayBoolNow) {
                if (!this.PlayBool) {
                    this.PlayBool = true;
                    this.soundChannel = this.sound.play(0, -1);
                }
                 this.soundChannel.volume = PrepareUI.MusicValue;
            }
            else {
                this.PlayBool = false;
                this.PlayBoolNow = false;
                this.soundChannel.stop();
            }          
        }
    }
    // /**声音控制器 */
    // class SoundManager {
    //     /**单例 */
    //     private static instance: SoundManager;

    //     /**获得单例 */
    //     public static getInstance(): SoundManager {
    //         if (this.instance == null) {
    //             this.instance = new SoundManager();
    //         }
    //         return this.instance;
    //     }
    //     /**背景音乐 */
    //     private bgSound: egret.Sound = null;
    //     /**音乐声道 */
    //     private bgChannel: egret.SoundChannel = null;
    //     /**当前音量 */
    //     public currentvolume: number = 1;

    //     /**播放背景音乐
    //      * @param name 背景音乐名字()
    //      */
    //     public Playbg(name: string): void {
    //         this.bgSound = RES.getRes(name);
    //         if (this.bgChannel != null) {
    //             this.bgChannel.stop();
    //         }
    //         this.bgChannel = this.bgSound.play(0);
    //         this.bgChannel.volume = this.currentvolume;
    //     }

    //     /**改变背景音乐音量
    //      * @param value 改变音量(建议在0-1之间)
    //      */
    //     public ChangebgVolume(value: number) {
    //         if (this.bgChannel != null) {
    //             this.bgChannel.volume = value;
    //         }
    //         this.currentvolume = value;
    //     }
    // }
}